/**
 * Created by Panda on 16/01/2017
 */
(function () {
    'use strict';


    var naviBInit = [{
        key: "all",
        icon: "book",
        content: "全部课件",
        queryParam: {}
    }, {
        key: "mine",
        icon: "user",
        content: "我的课件",
        queryParam: {}
    }, {
        key: "share",
        icon: "share",
        content: "我分享的课件",
        queryParam: {}
    }, {
        key: "publish",
        icon: "cloud",
        content: "我发布的课件",
        queryParam: {}
    }, {
        key: "verifyWait",
        icon: "star",
        iconColor:"yellow-normal",
        content: "未审核的课件",
        queryParam: {"q[statusCode]": "0"}
    }, {
        key: "verifyYes",
        icon: "star",
        iconColor:"green-light",
        content: "审核通过的课件",
        queryParam: {"q[statusCode]": "2"}
    }, {
        key: "verifyNo",
        icon: "star",
        content: "审核未通过的课件",
        queryParam: {"q[statusCode]": "-1"}
    }];

    var topBtns = [{
        key: "upload",
        icon: "cloud",
        text: "上传课件"
    }, {
        key: "group",
        icon: "folder",
        text: "新建分组"
    }, {
        key: "publish",
        icon: "share1",
        text: "批量发布"
    }, {
        key: "share",
        icon: "share",
        text: "批量分享"
    }, {
        key: "delete",
        icon: "delete",
        text: "批量删除"
    }, {
        key: "pass",
        icon: "checked",
        text: "审核通过"
    }];

    angular
        .module('com.akxx.aqzyk')
        .controller('CoursewareController', CoursewareController);


    /** @ngInject */
    function CoursewareController($timeout, $state, Storage, _Courseware) {
        var vm = this;

        vm.navi = $state.params.navi;

        vm.topBtns = topBtns;

        vm.topBtnEvent = function (key) {

        };

        vm.searchCallback = function (event) {
              console.log(event);
        };

        vm.toggleChecked = function (item) {
            if(item === "all"){
                var allCheck = vm.allChecked();
                angular.forEach(vm.list,function (item) {
                    item.check = !allCheck;
                });
            }else {
                item.check = !item.check;
            }
            console.log(item);
        };

        vm.allChecked = function () {
            var allCheck = vm.list && vm.list.length > 0;
            if(allCheck){
                for (var i in vm.list){
                    if(!vm.list[i].check){
                        allCheck = false;
                        break;
                    }
                }
            }
            return allCheck;
        };

        initNaviB();

        refreshList({async: true, pageSize: 25, pageIndex: 1});

        function initNaviB() {
            vm.naviBInit = naviBInit;
        }

        function refreshList(param) {
            _Courseware.Query.get(param).then(function (res) {
                console.log(res.data);
                vm.list = res.data;
            });
        }

    }

})();

